<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>My JSP 'verifyOrderOradeno.jsp' starting page</title>

		<script type="text/javascript">
	var initIndex = 0;
	function init() {
		return 10 * Math.random() + "";
		/*	$(function() {
				setTimeout(function() {
					$("#message").hide();
				}, 4000);
			});*/
	}
	function getAjaxOrders(id) {
		var tempString = "";
		$.ajax({
			type : 'post',
			url : '${ctx}/orders/detailed',
			data : 'id=' + id,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					tempString += "出库批次编号:" + data.content.shippedBatch.batch
							+ "<p>订单编号:" + data.content.ordeno + "<p>运单号:"
							+ data.content.waybillNo.expressNo + "<p>物流公司简称:"
							+ data.content.waybillNo.expressCompany
							+ "<p>收货人详细地址:" + data.content.receiverAddress
							+ "<p>省:" + data.content.receiverState + "<p>市:"
							+ data.content.receiverCity + "<p>区:"
							+ data.content.receiverDistrict + "<p>邮编:"
							+ data.content.receiverZip + "<p>会员昵称:"
							+ data.content.bunick + "<p>收货人名称:"
							+ data.content.receiverName + "<p>移动电话:"
							+ data.content.receiverMobile + "<p>固定电话:"
							+ data.content.receiverPhone + "<p>订单包含的商品数:"
							+ data.content.skuNum + "<p>物流公司名称:"
							+ data.content.caname + "<p>邮费:"
							+ data.content.posfee + "<p>来源店铺名:"
							+ data.content.shopname + "<p>会员昵称:"
							+ data.content.bunick;
					if (data.content.order_type == "single") {
						tempString = tempString + "<p>订单类型:一单一件";
					} else if (data.content.order_type == "multiple") {
						tempString = tempString + "<p>订单类型:一单多件件";
					}

					$.each(data.content.orderGoods, function(i) {
						tempString = tempString
								+ "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商品名称:"
								+ data.content.orderGoods[i].item_name;
						tempString = tempString
								+ "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商品数量:"
								+ data.content.orderGoods[i].quantity;
						tempString = tempString
								+ "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商品单价:"
								+ data.content.orderGoods[i].price;
						tempString = tempString
								+ "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;优惠金额:"
								+ data.content.orderGoods[i].promotion;
						tempString = tempString
								+ "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;应付金额:"
								+ data.content.orderGoods[i].payment;
						tempString = tempString
								+ "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;折扣:"
								+ data.content.orderGoods[i].discount;
					});

					tempString = tempString + "<p>订单总价:"
							+ data.content.totalPrice;
					$("#modalBody").html(tempString);
					$("#ss_" + id).attr("href", "#ordersDetailed");
				} else if (data.status == "-1") {
					alert("还没有得到该订单的详细信息！");
				}

			},

			error : function() {

			}
		});
	}

	function verifyOrderOradeno() {
		var ordeno = $("#ordeno" + initIndex).val();
		var expressNumber = $("#expressNumber" + initIndex).val();
		if (expressNumber.trim() == "") {
			alert("请填写运单号！");
			return;
		}
		if (ordeno.trim() == "") {
			alert("请填写订单号！");
			return;
		}
		$
				.ajax({
					type : 'post',
					url : '${ctx}/ediOrderSource/verifyOrderOradeno',
					data : 'ordeno=' + ordeno + '&expressNumber='
							+ expressNumber,
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							initIndex++;

							var numberDate = init();
							$("#message")
									.html(
											"验证成功!<a href=\"#ordersDetailed\" role=\"button\" data-toggle=\"modal\" id=\"ss_"
													+ data.content.ordeno
													+ "\" onclick=\"getAjaxOrders('"
													+ data.content.ordeno
													+ "')\">查看订单详情</a>");
							$("#message").attr("id",
									data.content.ordeno + numberDate);
							$("#bodyId")
									.append(
											"<div>订单号:&nbsp;<input type=\"text\" id=\"ordeno"
													+ initIndex
													+ "\" onchange=\"expressNumber()\" onfocus=\"this.style.imeMode='disabled'\"/>&nbsp;运单号:"
													+ "&nbsp;<input type=\"text\" id=\"expressNumber"
													+ initIndex
													+ "\""
													+ "onchange=\"verifyOrderOradeno()\" onfocus=\"this.style.imeMode='disabled'\"/>"
													+ "&nbsp;<button type=\"button\" class=\"btn btn-primary\""
													+ "onclick=\"verifyOrderOradeno()\">"
													+ "校验"
													+ "</button>"
													+ "<span id=\"message\"></span>"
													+ "</div>");
							$("#ordeno" + initIndex).focus();
						} else if (data.status == "0") {
							alert("订单号与运单号不匹配！");

							$("#ordeno" + initIndex).val("");
							$("#expressNumber" + initIndex).val("");
							$("#ordeno" + initIndex).focus();
						} else if (data.status == "-1") {
							alert("服务器异常！请稍后重试！");
						}
					},

					error : function() {
						alert("服务器异常！请稍后重试！");
					}
				});
	}
	function expressNumber() {
		$("#expressNumber" + initIndex).focus();
	}
</script>
	</head>

	<body>
		<div id="bodyId" style="height: 1000px; overflow: auto;">
			<div>
				订单号:
				<input type="text" id="ordeno0" onchange="expressNumber()"
					onfocus="this.style.imeMode='disabled'" />
				运单号:
				<input type="text" id="expressNumber0"
					onchange="verifyOrderOradeno()"
					onfocus="this.style.imeMode='disabled'" />
				<button type="button" class="btn btn-primary"
					onclick="verifyOrderOradeno()">
					校验
				</button>
				<span id="message"></span>
			</div>
		</div>
		<script type="text/javascript">
	$("#ordeno" + initIndex).focus();
</script>
		<div style="display: none; width: 1000" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="ordersDetailed">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
				<h3 id="myModalLabel">
					订单详细信息
				</h3>
			</div>
			<div class="modal-body" id="modalBody">

			</div>
			<div class="modal-footer">
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					Close
				</button>
			</div>
		</div>
	</body>
</html>
